package com.example.blogsystem.common;

import com.example.blogsystem.model.Userinfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description: session 工具类
 * User: DELL
 * Date: 2023-09-04
 * Time: 22:40
 */
public class SessionUtils {

    /**
     * 获取当前 session 中的用户信息
     * @param request
     * @return
     */
    public static Userinfo getUser(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if (session == null || session.getAttribute(AppVar.USER_SESSION_KEY) == null) {
            return null;
        }
        return (Userinfo) session.getAttribute(AppVar.USER_SESSION_KEY);
    }
}
